package com.dxf.hchat.controller;

import com.dxf.hchat.pojo.TbChatRecord;
import com.dxf.hchat.service.ChatRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/chatrecord")
public class ChatRecordController {

    @Autowired
    private ChatRecordService chatRecordService;


    /**
     * 查找聊天记录
     * @param userid
     * @param friendid
     * @return
     */
    @RequestMapping("/findByUserIdAndFriendId")
   public List<TbChatRecord> findByUserIdAndFriendId(String userid,String friendid){

       try {
           return chatRecordService.findByUserIdAndFriendId(userid,friendid);
       } catch (Exception e) {
           return new ArrayList<TbChatRecord>();
       }
   }

    /**
     * 查找未读的聊天记录
     * @param userid
     * @return
     */
    @RequestMapping("/findUnreadByUserid")
    public List<TbChatRecord> findUnreadByUserid(String userid){

        try {
            return chatRecordService.findUnreadByUserid(userid);
        } catch (Exception e) {
            return new ArrayList<TbChatRecord>();
        }
    }
}
